//控制引入FastClick后input点击迟钝问题
import fastClick from "fastclick"

if ('addEventListener' in document) {

  document.addEventListener('DOMContentLoaded', function() {

    fastClick.prototype.focus = (targetElement) => {
      let length
      if (
        targetElement.setSelectionRange &&
        targetElement.type.indexOf("date") !== 0 &&
        targetElement.type !== "time" &&
        targetElement.type !== "month"
      ) {
        length = targetElement.value.length
        targetElement.focus()
        targetElement.setSelectionRange(length, length)
      }
    }
    
    fastClick.FastClick.attach(document.body)

  }, {
    capture: false,  // 捕获-冒泡
    passive: true,   // 表示 listener 永远不会调用 preventDefault(), 提高移动端性能  
  });
}

function remSizeFn() {
  const clientW = document.documentElement.clientWidth;
  const clientH = document.documentElement.clientHeight;

  //  根据尺寸判断当前移动端是横屏还是竖屏
  const orientation = ( clientW > clientH ) ? "landscape" : "portrait";

	if(orientation === 'portrait'){
    document.documentElement.style.fontSize = clientW / 37.5 + "px";
		console.log('竖屏');
	} else {
    document.documentElement.style.fontSize = clientH / 37.5 + "px";
    console.log('横屏');
	}
}

//  初始化, 加载该文件的时候 立即执行
remSizeFn();

//  配置 rem, 1rem = 10px
window.onresize = function (ev) {
  remSizeFn();
};